## Figure 5a ##
## Run the regression models ("regression.R" file) before running the following commands ##
## Binary logistic regression ##
logit1 <-
  broom::tidy(logit) %>% filter(term != "(Intercept)") %>% mutate(model = "Model 1")
logit2 <-
  broom::tidy(logit_2) %>% filter(term != "(Intercept)") %>% mutate(model = "Model 2")

two_models <- rbind(logit1, logit2)

library(dotwhisker)
dwplot(two_models,
       vline = geom_vline(
         xintercept = 0,
         colour = "grey60",
         linetype = 2
       ),
       dot_args = list(aes(shape=model), size=4),
       whisker_args = list(aes(linetype=model), size=1.8),
       vars_order = c("postmat", "dissat", "postmat:dissat", "econdissat", "income", "dem", "polint", "poldis", "pertrust", "organ1", "educ", "ln_age", "sex1", "single1"),
       model_order = c("Model 1", "Model 2")
) %>% # plot line at zero _behind_coefs
  relabel_predictors(
    c(
      postmat = "Post-materialism",
      dissat = "Dissat.pol.system",
      econdissat = "Dissat.econ",
      income = "Income",
      dem = "Pro-dem attitude",
      polint = "Pol.interest",
      poldis = "Pol.discuss",
      pertrust = "Interpersonal trust",
      organ1 = "Organ.member",
      educ = "Education",
      ln_age = "log(age)",
      sex1 = "Female",
      single1 = "Single"
    )
  ) +
  theme_bw(base_size = 25) +
  xlab("Coefficient Estimate") + ylab("") +
  ggtitle("Coefficient plot (Binary logistic models)")+
  theme(
    plot.title = element_text(face = "bold", size=28),
    axis.text.x = element_text(size=22),
    axis.text.y = element_text(size=25),
    legend.position = c(0.75, 0.01),
    legend.justification = c(0, 0),
    legend.background = element_rect(colour = "grey80"),
    legend.text = element_text(size=25),
    legend.title = element_blank()
  ) +
  scale_colour_grey(
    start = .1,
    end = .1
  ) + 
  guides(shape = guide_legend(reverse = TRUE))

## Binary logistic regression with categorical explanatory variables ##
## Figure 5b ##
logit_cat_df <-
  broom::tidy(logit_cat) %>% filter(term != "(Intercept)") %>% mutate(model = "Model 3")
logit_cat2_df <-
  broom::tidy(logit_cat2) %>% filter(term != "(Intercept)") %>% mutate(model = "Model 4")

two_models <- rbind(logit_cat_df, logit_cat2_df)

dwplot(two_models,
       vline = geom_vline(
         xintercept = 0,
         colour = "grey60",
         linetype = 2
       ),
       dot_args = list(aes(shape=model), size=3.2),
       whisker_args = list(aes(linetype=model), size=1.8),
       dodge_size = 0.6,
       vars_order = c("postmat1", "postmat2", "dissat", "postmat1:dissat", "postmat2:dissat", "econdissat", "income", "dem", "polint2", "polint3", "polint4", "poldis2", "poldis3", "pertrust", "organ1", "educ1", "educ2", "educ3", "educ4", "educ5", "educ6", "educ7", "ln_age", "sex1", "single1"),
       model_order = c("Model 3", "Model 4")
) %>% # plot line at zero _behind_coefs
  relabel_predictors(
    c(
      postmat1 = "Mixed values",
      postmat2 = "Post-materialist",
      dissat = "Dissat.pol.system",
      econdissat = "Dissat.econ",
      income = "Income",
      dem = "Pro-dem attitude",
      polint2 = "Polint: Not very int",
      polint3 = "Polint: Somewhat int",
      polint4 = "Polint: Very int",
      poldis2 = "Poldis: Occasional",
      poldis3 = "Poldis: Frequently",
      pertrust = "Interpersonal trust",
      organ1 = "Organ.member",
      educ1 = "Primary education",
      educ2 = "Lower.sec.edu",
      educ3 = "Upper.sec.edu",
      educ4 = "Postsec.non-tert",
      educ5 = "Short-cyl tert",
      educ6 = "Bachelor",
      educ7 = "Master",
      ln_age = "log(age)",
      sex1 = "Female",
      single1 = "Single",
      "postmat1:dissat"="Mixed values*Dissat",
      "postmat2:dissat"="Post-materialist*Dissat"
    )
  ) +
  theme_bw(base_size = 25) +
  xlab("Coefficient Estimate") + ylab("") +
  ggtitle("Coefficient plot with categorical explanatory variables (Binary logistic models)")+
  theme(
    plot.title = element_text(face = "bold", size=16.5),
    axis.text.x = element_text(size=22), 
    axis.text.y = element_text(size=20),
    legend.position = c(0.75, 0.61),
    legend.justification = c(0, 0),
    legend.background = element_rect(colour = "grey80"),
    legend.text = element_text(size=25),
    legend.title = element_blank()
  ) +
  scale_colour_grey(
    start = .1,
    end = .1
  ) + 
  guides(shape = guide_legend(reverse = TRUE))

## Ordered logistic regression ##
## Figure 8a ##
ord1 <-
  broom::tidy(ord) %>% head(13) %>% mutate(model = "Model 1")
ord2 <-
  broom::tidy(ord_2) %>% head(11) %>% mutate(model = "Model 2")

two_models <- rbind(ord1, ord2)

dwplot(two_models,
       vline = geom_vline(
         xintercept = 0,
         colour = "grey60",
         linetype = 2
       ),
       dot_args = list(aes(shape=model), size=4),
       whisker_args = list(aes(linetype=model), size=1.8),
       vars_order = c("postmat", "dissat", "postmat:dissat", "econdissat", "income", "dem", "polint", "poldis", "pertrust", "organ1", "educ", "ln_age", "sex1", "single1"),
       model_order = c("Model 1", "Model 2")
) %>% # plot line at zero _behind_coefs
  relabel_predictors(
    c(
      postmat = "Post-materialism",
      dissat = "Dissat.pol.system",
      econdissat = "Dissat.econ",
      income = "Income",
      dem = "Pro-dem attitude",
      polint = "Pol.interest",
      poldis = "Pol.discuss",
      pertrust = "Interpersonal trust",
      organ1 = "Organ.member",
      educ = "Education",
      ln_age = "log(age)",
      sex1 = "Female",
      single1 = "Single"
    )
  ) +
  theme_bw(base_size = 25) +
  xlab("Coefficient Estimate") + ylab("") +
  ggtitle("Coefficient plot (Ordered logistic models)")+
  theme(
    plot.title = element_text(face = "bold", size=28),
    axis.text.x = element_text(size=22),
    axis.text.y = element_text(size=25),
    legend.position = c(0.75, 0.01),
    legend.justification = c(0, 0),
    legend.background = element_rect(colour = "grey80"),
    legend.text = element_text(size=25),
    legend.title = element_blank()
  ) +
  scale_colour_grey(
    start = .1,
    end = .1
  ) + 
  guides(shape = guide_legend(reverse = TRUE))

## Ordered logistic regression with categorical explanatory variables ##
## Figure 8b ##
ord_cat_df <-
  broom::tidy(ord_cat) %>% head(25) %>% mutate(model = "Model 3")
ord_cat2_df <-
  broom::tidy(ord_cat2) %>% head(25) %>% mutate(model = "Model 4")

two_models <- rbind(ord_cat_df, ord_cat2_df)
dwplot(two_models,
       vline = geom_vline(
         xintercept = 0,
         colour = "grey60",
         linetype = 2
       ),
       dot_args = list(aes(shape=model), size=3.2),
       whisker_args = list(aes(linetype=model), size=1.8),
       dodge_size = 0.6,
       vars_order = c("postmat1", "postmat2", "dissat", "postmat1:dissat", "postmat2:dissat", "econdissat", "income", "dem", "polint2", "polint3", "polint4", "poldis2", "poldis3", "pertrust", "organ1", "educ1", "educ2", "educ3", "educ4", "educ5", "educ6", "educ7", "ln_age", "sex1", "single1"),
       model_order = c("Model 3", "Model 4")
) %>% # plot line at zero _behind_coefs
  relabel_predictors(
    c(
      postmat1 = "Mixed values",
      postmat2 = "Post-materialist",
      dissat = "Dissat.pol.system",
      econdissat = "Dissat.econ",
      income = "Income",
      dem = "Pro-dem attitude",
      polint2 = "Polint: Not very int",
      polint3 = "Polint: Somewhat int",
      polint4 = "Polint: Very int",
      poldis2 = "Poldis: Occasional",
      poldis3 = "Poldis: Frequently",
      pertrust = "Interpersonal trust",
      organ1 = "Organ.member",
      educ1 = "Primary education",
      educ2 = "Lower.sec.edu",
      educ3 = "Upper.sec.edu",
      educ4 = "Postsec.non-tert",
      educ5 = "Short-cyl tert",
      educ6 = "Bachelor",
      educ7 = "Master",
      ln_age = "log(age)",
      sex1 = "Female",
      single1 = "Single",
      "postmat1:dissat"="Mixed values*Dissat",
      "postmat2:dissat"="Post-materialist*Dissat"
    )
  ) +
  theme_bw(base_size = 25) +
  xlab("Coefficient Estimate") + ylab("") +
  ggtitle("Coefficient plot with categorical explanatory variables (Ordered logistic models)")+
  theme(
    plot.title = element_text(face = "bold", size=16.5),
    axis.text.x = element_text(size=22),
    axis.text.y = element_text(size=20),
    legend.position = c(0.75, 0.61),
    legend.justification = c(0, 0),
    legend.background = element_rect(colour = "grey80"),
    legend.text = element_text(size=25),
    legend.title = element_blank()
  ) +
  scale_colour_grey(
    start = .1,
    end = .1
  ) + 
  guides(shape = guide_legend(reverse = TRUE))
